package com.wetalk.service;

import com.wetalk.service.impl.AuthImpl;
import com.wetalk.utils.MailService;
import com.wetalk.utils.VerificationCodeCreater;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * @author lijiaxing 2025-7-5
 */
@Service
public class AuthService implements AuthImpl {
    @Autowired
    private MailService mailService;
    @Autowired
    private VerificationCodeCreater vcc;
    @Autowired
    private com.wetalk.mapper.verification_code verification_code;

    public void sendEmail(String email){
        String code = vcc.generateCode();//生成验证码
        String s=new String("亲爱的用户，您好！\n" +
                "\n" +
                "感谢您注册 TT聊天，一个简洁高效的即时通讯平台。\n" +
                "\n" +
                "您的注册验证码为：【${code}】\n" +
                "请在 5 分钟内输入验证码完成注册。\n" +
                "\n" +
                "如果不是您本人操作，请忽略此邮件。\n" +
                "\n" +
                "—— TT聊天\n");
        String content = s.replace("${code}", code);

        mailService.sendSimpleMail(email,"TT聊天",content);//发送验证码
        verification_code.insert(email, code);//存入数据库
    }
}
